import random

import mss
import pygetwindow

import Config
from controller import Controller
from controller_card import ControllerCard
from game_over import GameOver

# 游戏窗口区域
# left表示距离屏幕左边多少像素
# top表示距离屏幕顶部多少像素
# width表示截图的宽度是多少像素
# height表示截图的高度是多少像素
position_window = {"left": 0, "top": 0, "width": 1000, "height": 570}
position_grab = {"left": 0, "top": 0, "width": 960, "height": 570}

with mss.mss() as sct:
    windows_ = pygetwindow.getWindowsWithTitle("雷电模拟器")[0]
    pos_dic = dict(position_window)
    windows_.resizeTo(pos_dic.get("width"), pos_dic.get("height"))
    windows_.moveTo(pos_dic.get("left"), pos_dic.get("top"))
    windows_.activate()

while True:
    value = random.randint(1, 5)
    print(f"value: {value}")
    if value > 2:
        # 刷卡
        c2 = ControllerCard(position_grab, "洛兰")
        c2.start()
        if c2.is_stop:
            break
    else:
        # 直达BOSS
        c1 = Controller(position_grab, Config.map_name)
        c1.start()
        if c1.is_stop:
            break

print("程序结束，关机")
GameOver.do(shutdown=False)
